const commentService = require("@/server/comment");
const { GetFromContext } = require("@/utils/gin_context");
const { successData, sendCode } = require("@/utils/r/result");

const comment = {
  async GetFrontList(req, res) {
    successData(res, await commentService.GetFrontList(req.query));
  },
  async Save(req, res) {
    sendCode(
      res,
      await commentService.Save(GetFromContext(req, "user_info_id"), req.body)
    );
  },
  async SaveLike(req, res) {
    const uid = GetFromContext(req, "user_info_id");
    const commentId = req.params.comment_id;
    sendCode(res, await commentService.SaveLike(uid, commentId));
  },
  // 根据 [评论id] 获取 [回复列表]
  async GetReplyListByCommentId(req, res) {
    const commentId = req.params.comment_id;
    successData(
      res,
      await commentService.GetReplyListByCommentId(commentId, req.query)
    );
  },
};

module.exports = comment;
